import os,threading,zipfile,re
from datetime import datetime


startTime = datetime.now()
lock = threading.Lock()
listFilePath = []

class MyThread(threading.Thread):

    def __init__(self,name):
        threading.Thread.__init__(self)
        self.name=name

    def run(self):
        while True:
            path=getPath()
            if path !="":
                with open(path, encoding="UTF-8") as file:
                    for line in file.readlines():
                        if strings in line:
                            print(path)
                            break
            else:
                break

def getPath():

    lock.acquire()
    if len(listFilePath)==0:
        lock.release()
        return ""
    else:
        filePath=listFilePath[0]
        del listFilePath[0]
    lock.release()
    return filePath


def Paths(path):
    for fileName in os.listdir(path):
        filePath = path + fileName
        listFilePath.append(filePath)
    return listFilePath

def jieya(pathSrc,pathSave):
    files=os.listdir(pathSrc)
    f=[]
    for i in files:
        if i.endswith(".zip"):
            f.append(i)
            p=pathSrc+"\\"+i
            zf=zipfile.ZipFile(p,"r")
            zf.extractall(pathSave)
            zf.close()
            os.remove(p)

def reFind(path, start, end):
    with open(path,encoding="UTF-8") as file:
        contents = file.read()
        pattern = f"{re.escape(start)}(.*?){re.escape(end)}"
        matches = re.findall(pattern, contents, re.DOTALL)
        return matches

if __name__ == '__main__':
    pathSrc=r"C:\Users\renjiang\Desktop\test"
    pathSave=r"C:\Users\renjiang\Desktop\test"

    Paths(pathSrc)
    strings="1"

    jieya(pathSrc,pathSave)

    thread1 = MyThread("t1")
    thread2 = MyThread("t2")
    thread1.start()
    thread2.start()
    thread1.join()
    thread2.join()
    endTime = datetime.now()
    print(f"查找时间：{(endTime - startTime).seconds}秒")
